{extend name="common/common" /}

{block name="style"}
<style type="text/css">
    .container-fluid .btn{
        float: right;
        margin-left: 10px;
    }
    .btn.btn-sm{
        margin: 0;
    }
    tr{
        cursor: pointer;
    }
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>会员列表</h5>
        </div>
        <div class="ibox-content">
            <form class="layui-form" action="" id="seaForm">
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" name="name" id="name" placeholder="会员名" class="layui-input">
                </div>

                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" name="phone" id="phone" placeholder="联系电话" class="layui-input">
                </div>

                <div class="layui-inline">
                    <button type="button" id="search" class="btn btn-info" style="margin-top: 2px;">查询</button>
                </div>
            </form>
            <div class="container-fluid">
                <div class="container-fluid">
                    {if authCheck('trash/delmem')}
                    <a class="btn btn-danger getIDs" href="javascript:delMem();" data-param=''><i class="fa fa-trash-o"></i>删除客户</a>
                    {/if}
                    {if authCheck('trash/recoverymem')}
                    <a class="btn btn-primary getIDs" href="javascript:recoveryMem();"><i class="fa fa-retweet"></i>恢复客户</a>
                    {/if}
                </div>
            </div>
            <table id="cusTable">
                <thead>
                <th>checkbox</th>
                <th class="text-center" data-field="id">会员ID</th>
                <th class="text-center" data-field="name">姓名</th>
                <th class="text-center" data-field="phone">联系电话</th>
                <th class="text-center" data-field="adress">地址</th>
                <th class="text-center" data-field="qq">QQ</th>
                <th class="text-center" data-field="weixin">微信</th>
                <th class="text-center" data-field="grade">等级</th>
                <th class="text-center" data-field="status">状态</th>
                <th class="text-center" data-field="first_relation">录入人</th>
                <th class="text-center" data-field="entry_time">录入时间</th>
                <th class="text-center" data-field="remarks">备注</th>
                {if authCheck('trash/member')}
                <th class="text-center" data-field="operate">操作</th>
                {/if}
                </thead>
            </table>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script type="text/javascript">
    var IDs = '';
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "{:url('trash/member')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
						resizable:true,//可变宽列表
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            columns : [{
                checkbox: true,
                formatter:function(value,row,index){
                    if (row.state == true){
                        return {
                            checked : value,//设置选中
                        };
                    }
                    return value;
                },
            }],
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    name:$('#name').val(),
                    phone:$('#phone').val(),
//                    seaPay:$("#seaPay").val(),
//                    seaEdu:$("#seaEdu").val(),
//                    searchText:$("#searchText").val()
                };
                return param;
            },
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            },
            onDblClickRow: function (row) {
                editbox = layer.open({
                    type:2,
                    title:'产品详情',
                    area:['80%','80%'],
                    content:"{:url('member/checkMember')}?id="+row.id,
                    btn:["确定"],
                    yes:function(){
                        layer.closeAll();
                        initTable();
                    }
                });
            }
        });
    }

    $(function(){
        //调用函数，初始化表格
        initTable();

        layui.use(['form'], function(){
            var form = layui.form;
        });

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

        $('.getIDs').on('click',function(){
            var checkedOn= $('#cusTable').bootstrapTable('getSelections');
            var IDs = '';
            for(var i=0;i<checkedOn.length;i++){
                if(i == 0){
                    IDs = checkedOn[0].id;
                }else{
                    IDs += ',' + checkedOn[i].id;
                }
            }
            $('.getIDs').attr('data-param',IDs);
        })
    });

    function delMem(ids=null){
        if(ids == null){
            ids = $('.getIDs').attr('data-param');
        }
        if(ids != ''){
            layer.confirm('确认删除这些数据?删除后不可恢复！', {icon: 3, title:'提示'}, function(index){
                $.post('./delMem',{ids:ids},function(res){
                    if(res.code == 1){
                        layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, initTable);
                    }else{
                        layer.msg(res.msg, {anim: 6});
                    }
                });
            });
        }else{
            layer.msg("请选择数据", {anim: 6});
        }
    }

    function recoveryMem(ids=null){
        if(ids == null){
            ids = $('.getIDs').attr('data-param');
        }
        if(ids != ''){
            layer.confirm('确认恢复这些数据?', {icon: 3, title:'提示'}, function(index){
                $.post('./recoveryMem',{ids:ids},function(res){
                    if(res.code == 1){
                        layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, initTable);
                    }else{
                        layer.msg(res.msg, {anim: 6});
                    }
                });
            });
        }else{
            layer.msg("请选择数据", {anim: 6});
        }
    }


</script>
{/block}
